package com.wwu.common.web;

import cn.hutool.captcha.LineCaptcha;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 验证码对象实体
 * @author 一蓑烟雨
 * @date 2021-10-26 16:03
 * @version 1.0.0
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value="CaptchaObj:验证码对象实体", description="验证码对象实体")
public class CaptchaObj {
    @ApiModelProperty(value = "验证码")
    private LineCaptcha captcha;

    @ApiModelProperty(value = "过期时间")
    private LocalDateTime expireTime;


    /**
     * 验证码及过期时间构造函数
     * @param captchaCode  验证码
     * @param expireAfterSeconds   多少分钟后过期
     * @return null
     * @author 一蓑烟雨
     * @date 2023/6/3 21:25
     */
    public CaptchaObj(LineCaptcha captcha,int expireAfterSeconds){
        this.captcha =captcha;
        this.expireTime = LocalDateTime.now().plusSeconds(expireAfterSeconds);
    }
    /**
     * 验证码是否过期
     * @return java.lang.Boolean
     * @author 一蓑烟雨
     * @date 2023/6/4 17:39
     */
    public Boolean isExpired(){
        return LocalDateTime.now().isAfter(this.expireTime);
    }
}
